package com.eboss.sbs.activity;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.eboss.sbs.R;
import com.eboss.sbs.activity.base.BaseActivity;
import com.mytools.tool.utils.ScreenUtils;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

public class ImageDescriptionActivity extends BaseActivity {
	
	private String title = "";
	private List<Integer> imgs = new ArrayList<Integer>(); 
	private LinearLayout picture_list;  
	Bitmap bitmap = null;
	LinearLayout.LayoutParams lp = null;
	int width = 0;
    int height = 0;
     
	@SuppressWarnings("unchecked")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		mActivity = this;
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_image_description);
		
		showView(R.id.titleback_btn_back, true);
		title = getIntent().getStringExtra("title");
		setTvText(R.id.tv_title, title);
		imgs = (List<Integer>) getIntent().getSerializableExtra("imgs");
		width = ScreenUtils.getScreenWidth(ImageDescriptionActivity.this);
		initView();
		display();
	}
	
	private void initView() {
		picture_list=(LinearLayout) findViewById(R.id.picture_list);
	}
	
	private void display() {
		for (Integer img: imgs) {
			final View view = getLayoutInflater().inflate(R.layout.listitem_imgurls, null);
			final ImageView iv = (ImageView)view.findViewById(R.id.image);
			Resources r = this.getResources();
			InputStream is = r.openRawResource(img);
			BitmapDrawable bmpDraw = new BitmapDrawable(is);
			bitmap = bmpDraw.getBitmap();
			lp = new LinearLayout.LayoutParams(width, height = bitmap.getHeight()*width/bitmap.getWidth());
			iv.setLayoutParams(lp);
			iv.setMaxWidth(width);
			iv.setMaxHeight(height);
			iv.setImageBitmap(bitmap);
			//iv.setBackgroundResource((int)img);
			picture_list.addView(view);
		}
	}

}
